package com.situ.mall.controller;

import com.situ.common.util.Result;
import com.situ.mall.pojo.entity.Footprint;
import com.situ.mall.pojo.entity.User;
import com.situ.mall.pojo.vo.FootprintVO;
import com.situ.mall.service.IFootprintService;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/footprint")
public class FootprintController {
    @Autowired
    private IFootprintService footprintService;

    @RequestMapping("/addFootprint")
    public Result addFootprint(Footprint footprint, HttpSession session) {
        User user = (User) session.getAttribute("user");
        Integer userId = user.getId();
        footprint.setUserId(userId);
        footprintService.addFootprint(footprint);
        return Result.ok("添加成功！");
    }
    @RequestMapping("/listFootprint")
    public Result listFootprint(HttpSession session) {
        User user = (User) session.getAttribute("user");
        Integer userId = user.getId();
        List<FootprintVO> list = footprintService.listFootprint(userId);
        System.out.println("--------------------------------------");
        System.out.println(list);
        return Result.ok(list);
    }
    @RequestMapping("/delete")
    public Result delete(Footprint footprint) {
        footprint.setIsDeleted((byte) 1);
        footprintService.delete(footprint);
        return Result.ok("删除成功！");
    }
}
